#!/bin/bash

INTERVAL=5
PREFIX=$INTERVAL-sec-status
RUNFILE=/home/benchmarks/running

mysql -e 'show global variables' >> mysql-variables

while test -e $RUNFILE;do
    file=$(date +%F_%I)
    sleep=$(date +%s.%N | awk "{print $INTERVAL - (\$1 % $INTERVAL)}")
    sleep $sleep
    ts="$(date +"TS %s.%N %F %T")"
    loadavg="$(uptime)"
    echo "$ts $loadavg" >> $PREFILE-$file-status
    mysql -e "show global status" >> $PREFILE-$file-status &
    echo "$ts $loadavg" >> $PREFILE-$file-innodbstatus
    myql -e "show engine innodb status\G" >> $PREFILE-$file-innodbstatus &
    echo "$ts $loadavg" >> $PREFILE-$file-processlist 
    mysql -e "show full processlist\G" >> $PREFILE-$file-processlist  &
    echo $ts
done
echo Exiting because $RUNFILE does not exist.
